#!/bin/bash
# if good then we can go for native speed.
# is it?
rm ~/.kali_lock
cat ~/.kali_ip | head --lines 1 | xargs -iabc -o bash -c "bash kali_native_vnc.sh abc || exit 0"
t=$(cat ~/.kali_ip | wc -c)
#echo $t
if [[ -f "~/.kali_ip" ]] || [ $t -lt 2 ]; then 
	# get that running in the background?
#if [ $? -ne 0 ] || [ $t -lt 2 ]; then 
	cd metalazero/remote_control/discovery
	# timeout this shit?
	#timeout 5 python3 broadcast_server.py --unique 1 &> ~/.kali_uuid &
	# will close the server after the whole thing right?
	rm ~/.kali_uuid
	bash ~/kali_connect.sh < ~/kali_execute_remote.sh | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | xargs -iabc python3 uuid_client.py -i abc >> ~/.kali_uuid
	#bash ~/kali_connect.sh < ~/kali_execute_remote.sh | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | xargs -iabc python3 broadcast_client.py -i abc
	# are you sure? when to check the shit?
	#sleep 5
	sed -i "s/'/\"/g" ~/.kali_uuid
	# check the file.
	#echo checking ~/.kali_uuid
	#cat ~/.kali_uuid
	python3 get_fastest_ip.py -f $HOME/.kali_uuid -u '6a752697-0f8c-4100-9405-b9abc24e84a8' > ~/.kali_ip
	cat ~/.kali_ip | head --lines 1 | xargs -iabc -o bash -c "bash kali_native_vnc.sh abc || exit 0"
	#cat ~/.kali_ip | head --lines 1 | xargs -iabc -o bash -c "bash ~/kali_native_connect.sh abc || exit 0"
	#cat ~/.kali_ip | xargs -iabc -o  bash ~/kali_native_connect.sh abc
fi
